#pragma once

namespace Tmpl {

template <typename T> class AABB;
template <typename T> 
class Ray
{
public:
	Ray() : mOrigin(T()), m_Dir(T()), mLength(10000000.0f) {};
	Ray( T origin, T dir, float length ) : mOrigin( origin ), mDir(dir), mLength(length){}
	Ray( T begin, T end ){ mOrigin = begin; mDir = end-begin; mLength = mDir.Length(); mDir/=mLength;}

	void SetOrigin( T origin ) { mOrigin = origin; }
	void SetDir( T dir ) { mDir = dir; }
	void SetLength( float length ) { mLength = length; }

	T GetOrigin() const { return mOrigin; }
	T GetEnd() const { return mOrigin + mDir * mLength; }
	T GetDir() const { return mDir; }
	T GetPosAlongRay(float dist) const { return mOrigin + mDir * dist; }
	float GetLength() const { return mLength; }

	float IntersectBox(const AABB<T>& bbox) const;
	float IntersectSphere(const T pos, const float radius) const;
private:
	T mOrigin;
	T mDir;
	float mLength;
};

typedef Ray<Vec2f> Ray2f;
typedef Ray<Vec3f> Ray3f;

} // Namespace